# -*- coding: utf-8 -*-
from django.contrib.syndication.views import Feed
from cmsdj.content.models import Content
from cmsdj.cfg.models import SiteCfg
from django.contrib.sites.models import Site
from django.core.exceptions import ObjectDoesNotExist

class LatestContentFeed(Feed):
    site = Site.objects.get_current()
    try:
        site_cfg = SiteCfg.current_cfg()
    except ObjectDoesNotExist:
        site_cfg = SiteCfg()

#    if (site_cfg == None):
#        title = "No hay un sitio definido"
#    else:
#        if (site_cfg.title == None):
#            site_cfg.title = u"Sitio sin título"
#        if (site_cfg.subtitle == None):
#            site_cfg.subtitle = u"Sitio sin subtítulo"
#        title = site_cfg.title + " | " + site_cfg.subtitle # Últimos contenidos publicados"
    title = unicode(site_cfg.title) + " | " + unicode(site_cfg.subtitle)
    link = "http://" + site.domain
    description = u"Últimos contenidos publicados."

    def items(self):
        return Content.objects.order_by('-modified')[:10]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        return item.description